package com.polaris.live.im.manager

import androidx.lifecycle.LifecycleOwner
import com.polaris.live.common.manager.CoroutineScopeManager
import com.polaris.live.utils.LifecycleListenerDispatcher
import kotlinx.coroutines.launch

/**
 * RouterControlManager  房間路由監聽控制
 * 只有接听这个   点击路由才可以收到信息
 * ps:这里仅限路由
 *
 * @author Created by 半仙 on 2024/4/13/013 17:26
 */
object RouterControlManager {

    private val routerControlManagerDispatcher =
        LifecycleListenerDispatcher<OnRouterControlListener>("RouterControlManager")

    /**
     * 添加监听
     */
    fun observeListener(owner: LifecycleOwner, listener: OnRouterControlListener) {
        routerControlManagerDispatcher.observe(owner, listener)
    }

    fun dispatchMessage(key: String, ext: Map<String, String>) {
        CoroutineScopeManager.mainScope.launch {
            routerControlManagerDispatcher.listeners.forEach {
                it.dispatcher(key, ext)
            }
        }
    }

    const val ROUTER_UP_MIC = "upMic" //上麦
    const val ROUTER_GIFT = "gift" //礼物盘拉起
    const val ROUTER_ROOMGAME = "roomGame" //拉起房间游戏
    const val ROUTER_PARTYGAMEUP = "partyGameUp" //上游戏位
}

fun interface OnRouterControlListener {

    fun dispatcher(key: String, ext: Map<String, String>)
}


